<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<% response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires", 0);%>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>文件上传</title>
	<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/jquery-1.6.min.js"></script>
	<%
		//java判断浏览器版本，防止异步加载js
		String agent = request.getHeader("User-Agent").toLowerCase();
		if(agent.indexOf("msie 8")>-1 || agent.indexOf("msie 9")>-1){
	%>
		<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/ajaxfileuploadie.js"></script>
	<% 
		}else{
	%>
		<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/ajaxfileupload.js"></script>
	<%
		}
	%>
	<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
	<script type="text/javascript">
		//上传
		function upfile() {
			var titleImg = $('#titleImg').val();

			if (titleImg == null || titleImg == '') {
				alert("请选择文件");
				return false;
			}

			var file = $("input[name='file']").val();
			var filename = file.replace(/.*(\/|\\)/, "");
			var fileExt = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : '';

			var able = "'png','jpg','docx','doc','ppt','pptx','xls','xlsx','pdf','txt','gif','rar','zip','sql','psd'";
			if (able.indexOf(fileExt) == -1) {
				alert("不允许上传" + fileExt + "格式的文件");
				return false;
			}

			var ifopen = "";
			if ($('#ifopen').is(':checked')) {
				ifopen = "0";
			} else {
				ifopen = "1";
			}
			var dialog = frameElement.dialog;
			//将异步上传改为表单提交
			document.getElementById("fileFormUpload").submit();
			/*
			$.ajaxFileUpload({
			url:'${pageContext.request.contextPath}/file/fileuploadsimple',
			dataType:'JSON',
			type:'post',
			secureuri: false, //一般设置为false  ,
			fileElementId: 'titleImg', //文件上传空间的id
			data:{
			filepath:$('#filePath').val(),
			ifopen:ifopen
			},
			success:function(data){
			if(data.code==-1){
			alert(data.msg);
			return;
			}
			parent.window.BindData();
			dialog.close();
			},
			error : function(data, status, e)//服务器响应失败处理函数
			{
			parent.window.BindData();
			dialog.close();
			}

			});
			*/
		}
	</script>
	<style type="text/css">
		.fl{
			float: left;
		}
		.file p{
			font-size: 12px;
			line-height: 30px;
			color: #666;
			margin-bottom: 10px;
		}
		.file div{
			height: 20px;
		}
		.file input {
			margin-left: 20px;
			font-size: 12px;
			color: #666;
		}
		.file input[type=file] {
			background: #f0f0f0;
		}
		#ifopen{
			margin-top: 18px;
			margin-top: 13px \0;
			*margin-top: 13px;
		}
		.file .label_check{
			height: 50px;
			line-height: 50px;
		}
		.file div label{
			margin-left: 6px;
			color: #666;
			font-size: 12px;
		}
		.file .upload_btn {
			width: 230px;
			height: 30px;
			line-height: 30px;
			background: #346bd0;
			color: #fff;
			outline: none;
			border: none;
		}
	</style>
</head>

<body>
	<form id="fileFormUpload" action="${pageContext.request.contextPath }/file/fileformupload" method="post" enctype="multipart/form-data">
		<input type="hidden" name="filepath" value="${filePath }" id="filePath">
		<input type="hidden" name="upid" value="${upid }" id="upid">
		<!-- 上传返回结果 -->
		<input type="hidden" id="rtn" value="${result }">
		<input type="hidden" id="selDepartId" name="selDepartId" value="${selDepartId }">
		<table align="center" class="file" width="280">
			<tr>
				<td>
					<p>请选择文件：</p>
					<div>
						<input id="titleImg" name="file" type="file" />
					</div>
				</td>
			</tr>
			<tr>
				<td>
						<div class="label_check">
							<input type="radio" id="ifopen1" name="fileCharacter" value="2" style="${grshow}" ${grcheck }/>
							<label for="ifopen1" style="${grshow}">个人文件</label>
							<input type="radio" id="ifopen2" name="fileCharacter" value="1" style="${bmshow}" ${bmcheck }/>
							<label for="ifopen2" style="${bmshow}">部门文件</label>
							<input type="radio" id="ifopen3" name="fileCharacter" value="0" style="${gxshow}"  ${gxcheck }/>
							<label for="ifopen3" style="${gxshow}">共享文件</label>
						</div>
						<input name="fileCharacter" value="${fileCharacter}" hidden/>
				</td>
			</tr>
			<tr>
				<td>
					<input class="upload_btn" type="button" value="上传" onclick="upfile();" />
				</td>
			</tr>
		</table>
	</form>
</body>
<script type="text/javascript">
	//上传结果返回
	var rtn = '${result}';
	$(function() {
		if (rtn != null && rtn != undefined && rtn != '') {
			var rtnJson = eval('(' + rtn + ')');
			if (rtnJson.code == 0) {
				try {
					parent.BindData(1);
					parent.$.ligerDialog.close();
					parent.operationTips('上传成功！');
					/* parent.$(".l-dialog,.l-window-mask").remove(); */
				} catch (e) {
					alert(e);
				}
			} else if (rtnJson.code == 1) {
				alert('上传失败！');
			}
		}
	});
</script>

</html>